package com.zxq.kingofbots.service.impl.ranklist;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zxq.kingofbots.mapper.UserMapper;
import com.zxq.kingofbots.pojo.User;
import com.zxq.kingofbots.service.ranklist.RanklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RanklistServiceImpl implements RanklistService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public JSONObject getRankList(Integer page) {
        IPage<User> userIPage=new Page<>(page,10);
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("rating");
        List<User> users = userMapper.selectPage(userIPage, queryWrapper).getRecords();
        Long count = userMapper.selectCount(null);
        for(User user:users){
            user.setPassword("");
        }
        JSONObject resp=new JSONObject();
        resp.put("users",users);
        resp.put("count",count);
        return resp;
    }
}
